﻿using MediatR;
using S.RBAC.Api.Application.Command.RoleJurisdictionCommand;
using S.RBAC.Infrastructure.Interface;

namespace S.RBAC.Api.Application.CommandHandlers.RoleJurisdictionHandler
{
    public class RoleJurisdictionDeleteCommandHandler : IRequestHandler<RoleJurisdictionDeleteCommand, int>
    {
        protected readonly IRoleJurisdictionRepository _roleJurisdiction;

        public RoleJurisdictionDeleteCommandHandler(IRoleJurisdictionRepository roleJurisdiction)
        {
            _roleJurisdiction = roleJurisdiction;
        }

        public async Task<int> Handle(RoleJurisdictionDeleteCommand request, CancellationToken cancellationToken)
        {
            var info = await _roleJurisdiction.GetRoleJurisdiction(request.RJId);

            if (info != null)
            {
                info.IsDel = true;
                _roleJurisdiction.UpdRoleJurisdiction(info);
                return 1;
            }

            return 0;
        }
    }
}
